home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / a_utils / _archvrs / unix / unzip51 / msdos / msdos.c < prev   
Encoding:
C/C++ Source or Header  |  1992-10-18  |  3.3 KB  |  125 lines

  1. /*---------------------------------------------------------------------------
  2.  
  3.   msdos.c
  4.  
  5.   MSDOS-specific routines for use with Info-ZIP's UnZip 5.1 and later.
  6.  
  7.   ---------------------------------------------------------------------------*/
  8.  
  9.  
  10. #include "unzip.h"
  11.  
  12. #ifdef __GO32__
  13.    void _dos_setftime(int, unsigned short, unsigned short);
  14.    void _dos_setfileattr(char *, int);
  15. #endif
  16.  
  17.  
  18.  
  19. /**********************/
  20. /* Function mapattr() */
  21. /**********************/
  22.  
  23. int mapattr()
  24. {
  25.     /* set archive bit (file is not backed up): */
  26.     pInfo->file_attr = (unsigned)crec.external_file_attributes | 32;
  27.     return 0;
  28.  
  29. } /* end function mapattr() */
  30.  
  31.  
  32.  
  33.  
  34.  
  35. /**************************************/
  36. /* Function set_file_time_and_close() */
  37. /**************************************/
  38.  
  39. void set_file_time_and_close()
  40.  /*
  41.   * MS-DOS VERSION
  42.   *
  43.   * Set the output file date/time stamp according to information from the
  44.   * zipfile directory record for this member, then close the file and set
  45.   * its permissions (archive, hidden, read-only, system).  Aside from closing
  46.   * the file, this routine is optional (but most compilers support it).
  47.   */
  48. {
  49. #ifdef __TURBOC__
  50.     union {
  51.         struct ftime ft;        /* system file time record */
  52.         struct {
  53.             ush ztime;          /* date and time words */
  54.             ush zdate;          /* .. same format as in .ZIP file */
  55.         } zt;
  56.     } td;
  57. #endif
  58.  
  59.  
  60. /*---------------------------------------------------------------------------
  61.      Do not attempt to set the time stamp on standard output.
  62.   ---------------------------------------------------------------------------*/
  63.  
  64.     if (cflag) {
  65.         close(outfd);
  66.         return;
  67.     }
  68.  
  69. /*---------------------------------------------------------------------------
  70.     Copy and/or convert time and date variables, if necessary; then set the
  71.     file time/date.
  72.   ---------------------------------------------------------------------------*/
  73.  
  74. #ifdef __TURBOC__
  75.     td.zt.ztime = lrec.last_mod_file_time;
  76.     td.zt.zdate = lrec.last_mod_file_date;
  77.     setftime(outfd, &td.ft);
  78. #else /* !__TURBOC__ */
  79.     _dos_setftime(outfd, lrec.last_mod_file_date, lrec.last_mod_file_time);
  80. #endif /* ?__TURBOC__ */
  81.  
  82. /*---------------------------------------------------------------------------
  83.     And finally we can close the file...at least everybody agrees on how to
  84.     do *this*.  I think...  Oh yeah, also change the mode according to the
  85.     stored file attributes, since we didn't do that when we opened the dude.
  86.   ---------------------------------------------------------------------------*/
  87.  
  88.     close(outfd);
  89.  
  90. #ifdef __TURBOC__
  91.     if (_chmod(filename, 1, pInfo->file_attr) != pInfo->file_attr)
  92.         fprintf(stderr, "\nwarning:  file attributes may not be correct\n");
  93. #else
  94.     _dos_setfileattr(filename, pInfo->file_attr);
  95. #endif
  96.  
  97. } /* end function set_file_time_and_close() */
  98.  
  99.  
  100.  
  101.  
  102.  
  103. #ifdef __GO32__
  104.  
  105. void _dos_setftime(int fd, ush dosdate, ush dostime)
  106. {
  107.     asm("pushl %ebx");
  108.     asm("movl %0, %%ebx": : "g" (fd));
  109.     asm("movl %0, %%ecx": : "g" (dostime));
  110.     asm("movl %0, %%edx": : "g" (dosdate));
  111.     asm("movl $0x5701, %eax");
  112.     asm("int $0x21");
  113.     asm("popl %ebx");
  114. }
  115.  
  116. void _dos_setfileattr(char *name, int attr)
  117. {
  118.     asm("movl %0, %%edx": : "g" (name));
  119.     asm("movl %0, %%ecx": : "g" (attr));
  120.     asm("movl $0x4301, %eax");
  121.     asm("int $0x21");
  122. }
  123.  
  124. #endif /* __GO32__ */
  125.